/**
 * 
 */
package fr.cephb.util;

/**
 * @author lindenb
 * methods for escaping strings
 */
public class C {
/**
 * escape a C string
 * @param seq the sequence to escape
 * @return the escaped sequence
 */
public static String escape(CharSequence seq)
	{
	StringBuilder b= new StringBuilder(seq.length());
	for(int i=0;i< seq.length();++i)
		{
		switch(seq.charAt(i))
			{
			case '\"':  b.append("\\\""); break;
			case '\'':  b.append("\\\'"); break;
			case '\n':  b.append("\\n"); break;
			case '\t':  b.append("\\t"); break;
			case '\r':  b.append("\\r"); break;
			default: b.append(seq.charAt(i)); break;
			}
		}
	return b.toString();
	}
}
